package com.weight.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.app.Activity;
import android.content.Intent;
import android.os.Environment;

public class Utilities {

	
    private static final float CONVERTING_UNIT = 2.20462262f;

	public static void goToBackground(Activity activity){
		Intent myIntent = new Intent(Intent.ACTION_MAIN);
        myIntent.addCategory(Intent.CATEGORY_HOME);
        activity.startActivity(myIntent);
	}

	public static float poundsToKilo(float weight) {
		weight = weight / CONVERTING_UNIT;
		return weight;
	}
	
	public static float kiloToPounds(float weight){
		weight = weight * CONVERTING_UNIT;
		return weight;
	}

    public static File createFileFromReport( String report ) {
        String directory = Environment.getExternalStorageDirectory() + "/weight"; 
        File folder = new File(directory);

        if ( !folder.exists() ) {
             folder.mkdir();
        }
        File file = null;
        try{
            file = new File(folder.getAbsolutePath()+Constants.FILE_SDCARD_REPORT_HTML);
            if(file.exists()) {
                file.delete();
            }
            file.createNewFile();
            OutputStream output = new FileOutputStream(file);
            output.write(report.getBytes());
            output.close();
        } catch(IOException e){
            e.printStackTrace();
        }
        return file;
    }
	
}
